﻿using System.Windows.Forms;

namespace LocationAwareness
{
    public class PoiComboBox: ComboBox
    {
        /// <summary>
        /// Method to add an POI to the ComboBox.
        /// </summary>
        /// <param name="poiDetail">
        /// Added instance of PoiDetail
        /// </param>
        public void AddPoi(PoiDetail poiDetail)
        {
            foreach (PoiDetail p in Items)
            {
                if(p.ObjectID == poiDetail.ObjectID)
                    return;
            }

            if (Items.Count == 10)
            {
                Items.RemoveAt(9);
            }

            Items.Insert(0, poiDetail);
        }

        /// <summary>
        /// Get an instance of PoiDetail, if
        /// PoiComboBox contains it.
        /// </summary>
        /// <param name="objectID">
        /// Object ID of the requestet PoiDetail
        /// </param>
        /// <returns>
        /// Instance of PoiDetail, specified by objectID
        /// </returns>
        public PoiDetail getPoiDetail(string objectID)
        {
            foreach (PoiDetail p in Items)
            {
                if (p.ObjectID == objectID)
                {
                    return p;
                }
            }
            return null;
        }
    }
}
